package com.lagou.niancheng.lagouservicegateway;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * com.lagou.niancheng.lagouservicegateway.AccessTokenFilterConf
 *
 * @author wlz
 * @date 2020/7/1
 */
@Configuration
public class AccessTokenFilterConf {

    @Bean
    public RouteLocator tokenRouteLocator(RouteLocatorBuilder builder,
                                          AccessTokenFilter accessTokenFilter) {
        return builder.routes()
                .route(r -> r.path("/api/user/test")
                        .filters(f -> f.stripPrefix(1).filter(accessTokenFilter))
                        .uri("lb://user-server")
                        .order(0)
                        .id("token_filter_router"))
                .build();
    }

}
